<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>王者荣耀轮播图基本实现</title>
  <link rel="stylesheet" href="./css/reset.css">
  <link rel="stylesheet" href="./css/common.css">
  <style>
    .main {
      height: 100px;
    }

    .news-section {
      display: flex;
      height: 342px;
    }

    .news-section .banner {
      width: 605px;
      background-color: #000;
      overflow: hidden;
    }

    .news-section .banner .image-list {
      display: flex;
      width: 604px;
      /* overflow: hidden; */
    }

    .news-section .banner .image-list .item {
      flex-shrink: 0;
      width: 100%;
    }

    .news-section .banner .image-list .item a {
      display: block;
    }

    .news-section .banner .image-list .item a img {
      width: 100%;
    }

    .news-section .banner .title-list {
      display: flex;
      height: 44px;
      line-height: 44px;
    }

    .news-section .banner .title-list .item {
      flex: 1;
      text-align: center;
    }

    .news-section .banner .title-list .item a {
      display: block;
      font-size: 14px;
      color: #b1b2be;
    }
    .news-section .banner .title-list .item.active a,
    .news-section .banner .title-list .item a:hover {
      color: #f3c258;
      background-color: rgba(255,255,255,.15);
    }

    .news-section .news {
      flex: 1;
      background-color: purple;
    }

    .news-section .download {
      width: 236px;
      background-color: skyblue;
    }

    .news-section .download a {
      display: block;
      background: url(./img/main_sprite.png) no-repeat;
    }

    .news-section .download a.download-btn {
      height: 128px;
      background-position: 0 -219px;
    }

    .news-section .download a.guard-btn {
      height: 106px;
      background-position: 0 -350px;
    }

    .news-section .download a.experience-btn {
      height: 108px;
      background-position: 0 -461px;
    }
  </style>
</head>
<body>

  <div class="main main_wrapper">
    <div class="news-section">
      <div class="banner">
        <ul class="image-list">
          <!-- <li class="item">
            <a href="">
              <img src="./img/banner_01.jpeg" alt="">
            </a>
          </li>
          <li class="item">
            <a href="">
              <img src="./img/banner_02.jpeg" alt="">
            </a>
          </li>
          <li class="item">
            <a href="">
              <img src="./img/banner_03.jpeg" alt="">
            </a>
          </li>
          <li class="item">
            <a href="">
              <img src="./img/banner_04.jpeg" alt="">
            </a>
          </li>
          <li class="item">
            <a href="">
              <img src="./img/banner_05.jpeg" alt="">
            </a>
          </li> -->
        </ul>
        <ul class="title-list">
          <!-- <li class="item active">
            <a href="#">桑启的旅途故事</a>
          </li>
          <li class="item">
            <a href="#">启示之音抢先听</a>
          </li>
          <li class="item">
            <a href="#">谁成为版本之子</a>
          </li>
          <li class="item">
            <a href="#">观赛体验升级</a>
          </li>
          <li class="item">
            <a href="#">季后赛开战</a>
          </li> -->
        </ul>
      </div>
      <div class="news"></div>
      <div class="download">
        <a class="download-btn" href="#"></a>
        <a class="guard-btn" href="#"></a>
        <a class="experience-btn" href="#"></a>
      </div>
    </div>
  </div>

  <script>
    const bannerData = [
      {
        title: "桑启的旅途故事",
        img: "./img/banner_01.jpeg",
        active: true
      },
      {
        title: "启示之音抢先听",
        img: "./img/banner_02.jpeg",
      },
      {
        title: "谁成为版本之子",
        img: "./img/banner_03.jpeg",
      },
      {
        title: "观赛体验升级",
        img: "./img/banner_04.jpeg",
      },
      {
        title: "季后赛开战",
        img: "./img/banner_05.jpeg",
      },
    ]

    const imageListEl = document.querySelector(".image-list")
    const titleListEl = document.querySelector(".title-list")

    bannerData.forEach((item, index) => {
      const isActive = item.active ? "active" : ""
      const imageItemEl = `
        <li class="item">
          <a href="#">
            <img src="${item.img}" alt="">
          </a>
        </li>
      `
      const titleItemEl = `
        <li class="item ${isActive}" data-index="${index}">
          <a href="#">${item.title}</a>
        </li>
      `
      imageListEl.innerHTML += imageItemEl
      titleListEl.innerHTML += titleItemEl
    })

    let titleActiveEl = document.querySelector(".title-list .active")
    titleListEl.onmouseover = function (e) {
      const target = e.target.parentElement
      if (target.classList.contains("item")) {
        titleActiveEl.classList.remove("active")
        target.classList.add("active")
        titleActiveEl = target

        const index = target.dataset.index
        imageListEl.style.transition = "transform .5s ease-in-out"
        imageListEl.style.transform = `translateX(${-index * 100}%)`
      }
    }

  </script>
  
</body>
</html>